﻿namespace 设备报警推送服务
{
    public partial class 特殊验证服务 : Form
    {
        public 特殊验证服务()
        {
            InitializeComponent();
        }

        string code = "";
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (tbVerificationCode.Text.Length > 2)
            {
                if (tbVerificationCode.Text == code)
                {
                    DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("授权码错误！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbVerificationCode.Text = "";
                }
            }
            else
            {
                MessageBox.Show("授权码未输入/错误！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbVerificationCode.Text = "";
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;

            this.Close();
        }

        private void 特殊验证服务_Load(object sender, EventArgs e)
        {
            tbVerificationCode.Focus();

            //数据验证码
            new Task(() =>
            {
                while (true)
                {
                    code = $"{DateTime.Now.ToString("dd")}{DateTime.Now.ToString("HH")}{DateTime.Now.ToString("mm")}";
                    Thread.Sleep(5 * 1000);
                }
            }).Start();
        }
    }
}
